/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hello.jni;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Properties;
import wiBase.WiException;
import wiBase.baseObject.Event;
import wiBase.baseObject.Node;
import wiBase.baseObject.Packet;
import wiModel.WiModelManager;
import wisimconsole.MainWiSim;

public class HelloWorld {

    public static final boolean FLAG_DEBUG = true;
    public ArrayList<String> data = new ArrayList<>();
    WiModelManager mng;

    public HelloWorld(WiModelManager mng) {
	this.mng = mng;
    }

    HelloWorld() {
    }

    public void addData(String item) {
	data.add(item);
    }

    public void addData(String wiObject, String[] attrib) {
	data.add(wiObject);

    }

    public void addAttrNetwork(String name, String value) {
	if (mng == null) {
	    return;
	}

	if (name.equals("width")) {
	    mng.setWidth(Double.valueOf(value));
	}
	if (name.equals("length")) {
	    mng.setLength(Double.valueOf(value));
	}
	if (name.equals("time")) {
	    mng.setDurationSimulation(Double.valueOf(value));
	}
    }

//    public void addNode(String[] attrName, String[] attrValue) {
//	if (mng == null) {
//	    return;
//	}
//	mng.addNode(Node.parseValue(attrName, attrValue));
//    }
//
//    public void addPacket(String[] attrName, String[] attrValue) {
//	if (mng == null) {
//	    return;
//	}
//	mng.addPacket(Packet.parseValue(attrName, attrValue));
//    }
//    HashMap<String, String> lstEvent = new HashMap<>();
//
//    public void addEvent(String[] attrName, String[] attrValue) {
//	if (mng == null) {
//	    return;
//	}
//	mng.addEvent(Event.parseValue(attrName, attrValue));
//    }

    public void setNode(Node[] list) throws WiException {
	mng._lstNodesOrg=new ArrayList<>();
	System.gc();
	System.out.println("size Nodes: " + list.length);
	for(Node item: list){
	    mng._lstNodesOrg.add(item);
	}
    }
    
    public void setPacket(Packet[] list) throws WiException {
	System.out.println("size Packets: " + list.length);
	for(Packet item: list){
	    
	    mng._lstPacketsOrg.add(item);
	}
    }
    
    public void setEvent(Event[] list) throws WiException {
	System.out.println("size Events: " + list.length);
	for(Event item: list){
	    mng._lstEventsOrg.add(item);
	}
    }

    public native void setEnv(int value);
    
    public native void setDebug(int isDebug);

    public native void parse(String text);
    public static String pathDLL="";
    static {
	pathDLL=MainWiSim.getDllPath();
//	String pathDLL = "G:/workspace_jni/HelloWorld/Release/CHelloWorld.dll";
//	String pathDLL = "H:\\workspace_nb\\WiSim\\WiSimConsole\\CHelloWorld.dll";
	File fDll = new File(pathDLL);
	if (fDll.exists()) {
	    System.load(pathDLL);
	} else {
	    String path = System.getProperty("user.dir");
	    Properties pr = System.getProperties();
	    File f = new File(path);
	    String parent = f.getParent();
	    if (FLAG_DEBUG) {
		System.out.print("local:" + parent);
	    }
	    System.load(f.getAbsolutePath() + "/CHelloWorld.dll");

	}
    }
}
